package com.wangchao.administrator.zenmechi.ui.fragment.caipufragment;

import com.wangchao.administrator.zenmechi.bean.caipubean.CaipuItem;
import com.wangchao.administrator.zenmechi.bean.caipubean.ResultBean;

import java.util.ArrayList;
import java.util.List;

import rx.Subscriber;

/**
 * Created by Administrator on 2016/10/17.
 */
public class CaipuPresenter implements CaipuContract.Presenter {

    private CaipuContract.View view;
    private CaipuContract.Model model;
    private List<String> items = new ArrayList<>();
    private List<String> ids = new ArrayList<>();
    private List<ResultBean> results;
    private MyAdapterForCaipuViewPager adapter;


    public CaipuPresenter(CaipuContract.View view) {
        this.view = view;
        this.model = new CaipuModel();
    }

    @Override
    public void getItems() {
        view.startAnim();
        model.getItems(new Subscriber<CaipuItem>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(CaipuItem caipuItem) {
                view.stopAnim();
                results = caipuItem.getResult();
                for (int i=0;i<results.size();i++){
                    items.add(results.get(i).getName());
                }

                for (int j=0;j<results.size();j++){
                    ids.add(results.get(j).getId()+"");
                }
                //Log.i("tag","----------"+items.size());
                view.initTablayout(items);
                view.initFragment(ids);
            }
        });
    }
}
